package com.platform.modules.mall.controller.associtag;

import com.platform.common.utils.StringUtils;
import com.platform.modules.mall.entity.MallActivityEntity;
import com.platform.modules.mall.entity.MallAssociTagEntity;
import org.springframework.stereotype.Service;

@Service("shopsActivityTag")
public class ShopsActivityTag extends AssociTagDataChangeAbs<MallActivityEntity>{

    @Override
    public boolean add(String associId, MallActivityEntity activityEntity) {
        if(activityEntity == null){
            return false;
        }
        if(!addVerify(associId,activityEntity.getId())){
            return false;
        }
        MallAssociTagEntity entity = new MallAssociTagEntity();
        if(activityEntity.getIsShow().equals(0)){
            return false;
        }
        // 活动标签
        entity.setAssociId(associId);
        entity.setTitle(activityEntity.getName());
        entity.setDescribe(activityEntity.getExtend1());
        entity.setType(MallAssociTagEntity.Type.OFFLINE_ACTIVITY.getValue());
        entity.setOtherId(activityEntity.getId());
        return tagService.add(entity);
    }

    @Override
    public boolean update(String otherId, MallActivityEntity entity) {
        if(StringUtils.isBlank(otherId)){
            return true;
        }
        tagService.lambdaUpdate()
                .set(MallAssociTagEntity::getTitle, entity.getName())
                .set(MallAssociTagEntity::getDescribe, entity.getExtend1())
                .set(MallAssociTagEntity::getType,3)
                .eq(MallAssociTagEntity::getOtherId,otherId)
                .update();
        this.associUpdate(otherId,entity);
        return true;
    }

    @Override
    public boolean associAdd(MallActivityEntity entity,String... otherId) {
        if(otherId == null || otherId.length <= 0){
            return true;
        }
        return tagService.lambdaUpdate()
                .set(MallAssociTagEntity::getDescribe,entity.getName())
                .set(MallAssociTagEntity::getType,2)
                .set(MallAssociTagEntity::getOtherId1,entity.getId())
                .in(MallAssociTagEntity::getOtherId,otherId)
                .update();
    }

    @Override
    public boolean associUpdate(String otherId1, MallActivityEntity entity) {
        if(StringUtils.isBlank(otherId1)){
            return true;
        }
        return tagService.lambdaUpdate()
                .set(MallAssociTagEntity::getDescribe,entity.getName())
                .set(MallAssociTagEntity::getType,2)
                .eq(MallAssociTagEntity::getOtherId1,otherId1)
                .update();
    }

    @Override
    public boolean associDelate(String... otherId1) {
        if(otherId1 == null || otherId1.length <= 0){
            return true;
        }
        return tagService.lambdaUpdate()
                .set(MallAssociTagEntity::getDescribe,null)
                .set(MallAssociTagEntity::getOtherId1,null)
                .set(MallAssociTagEntity::getType,1)
                .in(MallAssociTagEntity::getOtherId1,otherId1)
                .update();
    }

}
